package com._system._g;

import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;

import com._system.RunConfig;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.ICallback;
import com.jfinal.plugin.druid.DruidPlugin;
import com.laymi.common.model._MappingKit;

public class test {
    public static void startPlugin() {
        PropKit.use("a_little_config.txt");
        DruidPlugin druidPlugin = new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
        ActiveRecordPlugin arp = new ActiveRecordPlugin("mysql",druidPlugin);
        _MappingKit.mapping(arp);
        
        druidPlugin.start();
        arp.start();
    }
    public static DataSource getDataSource() {
        PropKit.use("a_little_config.txt");
        DruidPlugin druidPlugin = RunConfig.createDruidPlugin();
        druidPlugin.start();
        return druidPlugin.getDataSource();
    }
    public static void main(String[] args) throws SQLException {
        DatabaseMetaData dbMeta = getDataSource().getConnection().getMetaData();
        System.out.println(dbMeta.getTypeInfo());
        ResultSet rs = dbMeta.getTables(getDataSource().getConnection().getCatalog(), null, null, new String[]{"TABLE", "VIEW"});
        String primaryKey = "";
        int index = 0;
        while (rs.next()) {
            if (index++ > 0) {
                primaryKey += ",";
            }
            primaryKey += rs.getString("TABLE_NAME");
        }
        System.out.println(primaryKey);//blog,g_log,g_table,g_table_column,note,test,upload_counter,user,table
        ResultSet rs2 =  dbMeta.getColumns(getDataSource().getConnection().getCatalog(), null, "blog", "");
        String primaryKey1 = "";
        int index1 = 0;
        while (rs2.next()) {
            System.out.println("表名="+rs2.getString("COLUMN_NAME"));
            System.out.println("列数据类型标识="+rs2.getString("DATA_TYPE"));
            System.out.println("列数据类型String="+rs2.getString("TYPE_NAME"));
            System.out.println("字段长度"+rs2.getString("COLUMN_SIZE"));
            if (index1++ > 0) {
                primaryKey1 += ",";
            }
            primaryKey1 += rs2.getString("TABLE_NAME");
        }
        System.out.println(primaryKey1);
        //查询数据库表名和注释
        //选择数据库表导入，生成table表和字段表包括字段类型和java字段类型
        //然后编辑table和字段表然后生成model basemodel，mapping，sql，table，add，edit，
        //
    }
}
